#! /bin/bash
if [ -n "$APTPROXY" ]; then
ainsl -a /etc/apt/apt.conf.d/02proxy "Acquire::http::Proxy \"$APTPROXY\";"
ainsl  /etc/apt/apt.conf.d/02proxy 'Acquire::https::proxy "DIRECT";'
else
    rm -f $target/etc/apt/apt.conf.d/02proxy
fi
echo "DPkg::Progress-Fancy "true";" > $target/etc/apt/apt.conf.d/01color
echo "APT::Color "true";" >> $target/etc/apt/apt.conf.d/01color
echo force-unsafe-io > $target/etc/dpkg/dpkg.cfg.d/unsafe-io

ainsl -a /etc/apt/apt.conf.d/03download 'Acquire::Queue-Mode "access";'
ainsl /etc/apt/apt.conf.d/03download 'Acquire::Retries "3";'
ainsl /etc/apt/apt.conf.d/03download 'Acquire::CompressionTypes::Order "lzma";'
ainsl /etc/apt/apt.conf.d/03download 'Acquire::ForceIPv4 "true";'
# you may want to add i386 arch to amd64 hosts
# if ifclass AMD64; then
#     $ROOTCMD dpkg --add-architecture i386
# fi
cp -f /etc/apt/trusted.gpg.d/*.gpg $target/etc/apt/trusted.gpg.d/

# use external mirror, remove this script when using a mirror from CD

cat <<EOM > $target/etc/apt/sources.list
# external mirror
deb MIRRORURL $ubuntudist main restricted universe multiverse
deb MIRRORURL $ubuntudist-updates main restricted universe multiverse
deb MIRRORURL $ubuntudist-security main restricted universe multiverse
deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $ubuntudist stable
#deb http://ppa.launchpad.net/ansible/ansible/ubuntu $ubuntudist main
deb http://ppa.launchpad.net/zfs-native/stable/ubuntu $ubuntudist main

#Oracle Java 8
#deb http://ppa.launchpad.net/webupd8team/java/ubuntu $ubuntudist main
#deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu $ubuntudist main
EOM

# determine a fast mirror for Ubuntu
list=$(curl -s http://mirrors.ubuntu.com/mirrors.txt)
mirror=$(netselect $list | awk '{print $2}')
sed -i -e "s#MIRRORURL#$mirror#" $target/etc/apt/sources.list
